import { fetch } from "@/core/requset";

// 登录方法
export function login(data) {
  return fetch({
    url: "/mh/login",
    method: "POST",
    data,
  });
}

// 退出方法
export function logout() {
  return fetch({
    url: "/mh/logout",
    loading: true,
    method: "POST",
  });
}

export const xdGlysfqy = (params) => {
  return fetch({
    url: `/mh/xdGlysfqy`,
    data: JSON.stringify(params),
    method: "POST",
  });
};

// 修改密码
export function resetPassword(params) {
  return fetch({
    url: "/user/resetPassword",
    method: "POST",
    data: JSON.stringify(params),
  });
}

// 重置密码
export function resetQymm(params) {
  return fetch({
    url: "/user/resetQymm",
    method: "POST",
    data: JSON.stringify(params),
  });
}

// ========== OAUTH 2.0 相关 ==========

export function authorize(
  responseType,
  clientId,
  redirectUri,
  state,
  autoApprove
) {
  // 构建 scopes
  const scopes = {};
  /* for (const scope of checkedScopes) {
    scopes[scope] = true
  }
  for (const scope of uncheckedScopes) {
    scopes[scope] = false
  } */
  // 发起请求
  return fetch({
    url: "/oauth2/authorize",
    headers: {
      "Content-type": "application/x-www-form-urlencoded",
    },
    params: {
      response_type: responseType,
      client_id: clientId,
      redirect_uri: redirectUri,
      state,
      auto_approve: autoApprove,
      scope: JSON.stringify(scopes),
    },
    method: "post",
  });
}
